using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Web.Shop.Member;
using System;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Member_MBF_MyGiftCards : Member, IRequiresSessionState
{
	protected DropDownList DropType;
	protected TextBox txtFaceValueQuery;
	protected TextBox begindate;
	protected TextBox EndDate;
	protected Button sb;
	protected GridView GridView1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.GridView1.PageIndexChanging += new GridViewPageEventHandler(this.GridView1_PageIndexChanging);
		if (!base.IsPostBack)
		{
			string groupPower = base.user.GetGroupPower("GroupPower");
			if (!groupPower.Contains("showgiftcard"))
			{
				this.WriteErrMsg("", Language.GetAdminMsg("Common/RightErr"), Fetch.Referrer);
			}
			this.DropType.bindTableToDropDownList(Blls.bllFestival.GetDropDownListData(""), false, true);
		}
		this.begindate.Attributes.Add("onclick", "SelectDate(" + this.begindate.UniqueID + ",'yyyy-MM-dd');");
		this.EndDate.Attributes.Add("onclick", "SelectDate(" + this.EndDate.UniqueID + ",'yyyy-MM-dd');");
	}
	private void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.GridView1.PageIndex = e.NewPageIndex;
		this.BindGridView();
	}
	protected void BindGridView()
	{
		this.GridView1.DataSource = Blls.bllGiftCard.GetListRowid(2147483647, this.GetQuestString(), "Rowid asc", new string[0]).Tables[0];
		this.GridView1.DataBind();
	}
	protected string GetQuestString()
	{
		string text = string.Format(" (BuyID={0} or RecieveID={0} ) ", base.user.UserID);
		string selectValue = this.DropType.GetSelectValue(new string[0]);
		if (selectValue != "")
		{
			text += string.Format(" and FestivalName='{0}' ", selectValue);
		}
		string text2 = this.txtFaceValueQuery.Text.Trim();
		if (text2 != "")
		{
			decimal d = 0m;
			bool flag = decimal.TryParse(text2, out d);
			if (flag && d > 0m)
			{
				text += string.Format(" and FaceValue={0} ", text2);
			}
			else
			{
				this.txtFaceValueQuery.Text = "";
			}
		}
		string text3 = this.begindate.Text;
		if (text3 != string.Empty)
		{
			try
			{
				Convert.ToDateTime(text3);
			}
			catch
			{
				this.WriteErrMsg("", Language.Get("Common/DateTimeFormatErr"), "");
			}
			text = text + "and datediff(dd,BuyTime,'" + text3 + "')<=0 ";
		}
		string text4 = this.EndDate.Text;
		if (text4 != string.Empty)
		{
			try
			{
				Convert.ToDateTime(text4);
			}
			catch
			{
				this.WriteErrMsg("", Language.Get("Common/DateTimeFormatErr"), "");
			}
			if (!string.IsNullOrEmpty(text3) && Convert.ToDateTime(text4) < Convert.ToDateTime(text3))
			{
				this.WriteErrMsg("", Language.Get("Common/DateTimeErr"), "");
			}
			text = text + "and datediff(dd,BuyTime,'" + text4 + "')>=0 ";
		}
		return text;
	}
	protected void Search_OnClick(object sender, EventArgs e)
	{
		this.BindGridView();
	}
	protected string GetUserName(object obj)
	{
		int value = obj.IsNull(new object[0]).ToInt32(new int[0]);
		return StaticFun.GetUserNameByid(new int?(value));
	}
	protected string DisplayPwd(object o_pwd, object o_buyid, object o_receiveid)
	{
		int num = o_buyid.IsNull(new object[0]).ToInt32(new int[0]);
		int num2 = o_receiveid.IsNull(new object[0]).ToInt32(new int[0]);
		string text = o_pwd.IsNull(new object[0]);
		string result;
		if (num2 > 0 && num2 != base.user.UserID)
		{
			result = "";
		}
		else
		{
			result = text;
		}
		return result;
	}
	protected string GetQueryUrl(object fv, object bl, object cn)
	{
		string result;
		if (fv.ToDecimal2() > bl.ToDecimal2())
		{
			result = "<a href='MBF_UserCardRecode.aspx?CardType=-2&CardNumber=" + cn.IsNull(new object[0]) + "'><img style=\"width:16px;height:16px;\" alt=\"查询本张卡使用记录\" src='images/record_16x16.gif' /></a>";
		}
		else
		{
			result = "";
		}
		return result;
	}
}
